/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * <p>Project: jse2302 - FileCopyDemo
 * <p>Powered by webrx On 2023-06-27 09:58:37
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class FileCopyDemo {
    public static void main(String[] args) {
        System.out.println("\"\\");
        //"\
        //实现文件复制功能 c:\abc\a.jpg
        String path = "c:/abc/a.jpg";
        File f = new File(path);
        System.out.println(f.getAbsolutePath());
        String dst = "abc.jpg";
        long ss = System.currentTimeMillis();
        try (var i = new FileInputStream(path); var o = new FileOutputStream(dst)) {

            //10k
            byte[] buf = new byte[10240];
            int len = 0;// !=-1  >=0 >0
            while ((len = i.read(buf)) > 0) {
                System.out.println(len);
                o.write(buf, 0, len);


            }
            System.out.println(len);

            //单字节复制到新文件
            //int b = 0;
            //while((b=i.read())!=-1){
            //    o.write(b);
            //}

            //新功能 8k
            //i.transferTo(o);


        } catch (Exception e) {

        }
        long ee = System.currentTimeMillis();
        System.out.println(ee - ss);
    }
}
